import { Hover } from "vscode-languageserver";
import { t } from "./analysis";
import { getNodeWithPathAtPosition, makeDocumentFromSymbol } from "./util";

export const emptyHover: Hover = { contents: [] };

export async function provideHover(source: t.SourceFile, position: number): Promise<Hover | null> {
    const nodeResult = getNodeWithPathAtPosition(source, position);
    if (!nodeResult.node || !nodeResult.node.symbol || nodeResult.path.preProErrorNode || nodeResult.path.preProLineNode) {
        return null;
    }
    return {
        contents: {
            kind: "markdown",
            value: makeDocumentFromSymbol(nodeResult.node.symbol, nodeResult.node, true),
        },
        range: {
            start: source.getLineAndCharactorOfPosition(nodeResult.node.start),
            end: source.getLineAndCharactorOfPosition(nodeResult.node.end)
        }
    };
}

